/**
 * 
 */
package com.archerdu.apply.service.impl;

import java.util.List;

import com.archerdu.apply.dao.ArticleCatalogDAO;
import com.archerdu.apply.dao.ArticleDAO;
import com.archerdu.apply.model.Article;
import com.archerdu.apply.model.ArticleCatalog;
import com.archerdu.apply.service.ArticleManager;
import com.archerdu.base.dao.IBaseDao;
import com.archerdu.base.service.BaseManager;

/**
 * @author archer
 * @version 1.0.0
 */
public class ArticleManagerImpl extends BaseManager<Article, String> implements
        ArticleManager {

    private static final long serialVersionUID = 8596375322783640728L;

    private ArticleDAO articleDao;
    private ArticleCatalogDAO    articleCatalogDao;

    @Override
    public void add(Article entity) throws Exception {
        ArticleCatalog cate = articleCatalogDao.get(entity.getCatalogId());
        entity.setCatalogCode(cate.getCode());
        entity.setCreatetime(getSqlDate());
        
        super.add(entity);
    }

    public void setArticleDao(ArticleDAO dao) {
        articleDao = dao;
    }

    public ArticleDAO getArticleDao() {
        return articleDao;
    }

    @Override
    protected IBaseDao<Article, String> getDao() {
        return (IBaseDao<Article, String>) articleDao;
    }

    public ArticleCatalogDAO getArticleCatalogDao() {
        return articleCatalogDao;
    }

    public void setArticleCatalogDao(ArticleCatalogDAO articleCatalogDao) {
        this.articleCatalogDao = articleCatalogDao;
    }

	@Override
	public List<Article> getLatest(String cateId, Integer recommend,
			Integer count) {
		return getArticleDao().getLatest(cateId, recommend, count);
	}

}
